﻿using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

namespace PickGold.Api
{
	public static class Hid
	{
		public const string DLL = ApiUtil.DLL_HID;

		/// <summary>
		/// 获取一个可用的GUID函数，因为每一个设备驱动都需要一个唯一标识那就是GUID。
		/// </summary>
		/// <param name="gHid"></param>
		[DllImport(DLL, SetLastError = true)]
		public static extern void HidD_GetHidGuid(out Guid gHid);

		//获取一个打开的设备的详细信息到内存 
		[DllImport(DLL, SetLastError = true)]
		public static extern bool HidD_GetPreparsedData(IntPtr hFile, out IntPtr lpData);

		//释放上一个函数所处理的内存 
		[DllImport(DLL, SetLastError = true)]
		public static extern bool HidD_FreePreparsedData(ref IntPtr pData);

		//从HidD_GetPreparsedData函数处理的内存中获取设备的可用信息 
		[DllImport(DLL, SetLastError = true)]
		public static extern int HidP_GetCaps(IntPtr lpData, out HidCaps oCaps);
	}

	[StructLayout(LayoutKind.Sequential)]
	//public unsafe struct HidCaps
	public struct HidCaps
	{
		public ushort Usage;
		public ushort UsagePage;
		public ushort InputReportByteLength;
		public ushort OutputReportByteLength;
		public ushort FeatureReportByteLength;
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
		public ushort[] Reserved; // USHORT Reserved[17]，   
		public ushort NumberLinkCollectionNodes;
		public ushort NumberInputButtonCaps;//
		public ushort NumberInputValueCaps;//
		public ushort NumberInputDataIndices;//
		public ushort NumberOutputButtonCaps;
		public ushort NumberOutputValueCaps;
		public ushort NumberOutputDataIndices;
		public ushort NumberFeatureButtonCaps;
		public ushort NumberFeatureValueCaps;
		public ushort NumberFeatureDataIndices;
	}
}